package entities.concept;

import option.KBVocabulary;
import utils.Display;
import entities.role.Role;

public final class ExistsConcept extends QuantifiedConcept {

	public ExistsConcept(Role role, Concept filler) {
		super(role, filler);
	}

	private volatile int hashCode = 0;

	@Override
	public int hashCode() {
		if (hashCode != 0) {
			return hashCode;
		}
		final int prime = 31;
		int result = 1;
		result = prime * result + ((filler == null) ? 0 : filler.hashCode());
		result = prime * result + ((role == null) ? 0 : role.hashCode());
		hashCode = result;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!(obj instanceof ExistsConcept))
			return false;
		ExistsConcept other = (ExistsConcept) obj;
		if (filler == null) {
			if (other.filler != null)
				return false;
		} else if (!filler.equals(other.filler))
			return false;
		if (role == null) {
			if (other.role != null)
				return false;
		} else if (!role.equals(other.role))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return Display.SOMEUNICODE + " " + role.toString() + ".("
				+ filler.toString() + ")";
	}

	@Override
	public Concept getPrimeCopy() {
		return new ExistsConcept(Role.createRoleAsIs(this.role.getRoleName()
				+ Concept.PRIME), filler.getPrimeCopy());
	}

	@Override
	public String toSerializedString() {
		return " (" + KBVocabulary.SOME + " " + this.role.toSerializedString()
				+ " " + this.filler.toSerializedString() + ") ";
	}

	@Override
	public boolean hasUniversalInside() {
		return this.filler.hasUniversalInside();
	}

}
